<template>
    <Card>
      <VerticalToggle>
        <MldSearch ref="search" v-if="searchable" class="search" @on-search="handleSearch(...arguments, vm)"></MldSearch>
      </VerticalToggle>
      <Row class="mld-toolbar" style="margin-bottom:10px;">
        <Col span="16">
          <Button v-has="'admin,wzyy:cloudbaeBatch:save'" shape="circle" type="primary" icon="md-add" @click="openAdd(vm)">{{vm.$t('add')}}</Button>
          <Button :disabled="selection.length!=1" v-has="'admin,wzyy:cloudbaeBatch:update'" shape="circle" type="success" icon="ios-create" @click="openEdit(vm)">{{vm.$t('edit')}}</Button>
          <Poptip confirm :title="vm.$t('delete-tips')" @on-ok='handleRemove(selection, vm)'>
             <Button :disabled="selection.length==0" v-has="'admin,wzyy:cloudbaeBatch:remove'" shape="circle" type="error" icon="md-close">{{vm.$t('delete')}}</Button>
          </Poptip>
          <Button :disabled="selection.length!=1" v-has="'admin,wzyy:cloudbaeBatch:setApplyRecordStartAndEndTime'" shape="circle" type="info" icon="md-time" @click="openSetApplyRecordStartAndEndTimeForm(vm)">按批次设置卡券有效期</Button>
          <Poptip confirm :title="'按该批次创建核销券'" @on-ok='handleCreateTicketBycloudbaeBatch(selection, vm)'>
            <Button :disabled="selection.length!=1" v-has="'admin,wzyy:cloudbaeBatch:createTicketBycloudbaeBatch'" shape="circle" type="info" icon="md-checkbox">按批次创建卡券</Button>
         </Poptip>
        </Col>
        <Col span="8">
          <ButtonGroup style="float:right">
            <Button icon="md-search" @click="handleSearchable(vm)"></Button>
            <Button icon="md-refresh" @click="handleRefresh(vm)"></Button>
          </ButtonGroup>
        </Col>
     </Row>
     <Table
     @on-selection-change='handleSelectionChange(...arguments, vm)'
     :loading="loading" stripe :columns="columns" :data="tableData"></Table>
      <Page class="mld-page"
      :current='pageIndex'
      :page-size='pageSize'
      @on-change='handlePageIndexChange(...arguments, vm)'
      @on-page-size-change='handlePageSizeChange(...arguments, vm)'
      show-total
      show-elevator
      show-sizer
      transfer
      style="margin-top:10px;"
      :prev-text="vm.$t('prev-text')" :next-text="vm.$t('next-text')" :total="recordCount"></Page>
    </Card>
</template>

<script>
import MldSearch from './components/search'
import handleBtns from './handle-btns'
import methods from './methods'
export default {
  components: {
    MldSearch
  },
  data () {
    return {
      modalAdd: true,
      searchable: false,
      fullscreen: false,
      loading: false,
      pageIndex: this.$config.pageIndex,
      pageSize: this.$config.pageSize,
      recordCount: 0,
      selection: [],
      columns: [
        {type: 'selection', width: 60, align: 'center'},
        {
          title: '文件名',
          key: 'fileName',
          render: (h, params) => {
            return h('div', params.row.fileName)
          }
        },
        {
          title: '文件路径',
          key: 'filePath',
          render: (h, params) => {
            return h('div', params.row.filePath)
          }
        },
        {
          title: '文件大小',
          key: 'fileSize',
          render: (h, params) => {
            return h('div', params.row.fileSize + 'kb')
          }
        },
        {
          title: '记录数',
          key: 'recordCount',
          render: (h, params) => {
            return h('div', params.row.recordCount)
          }
        },
        {
          title: '状态',
          key: 'status',
          render: (h, params) => {
            // 状态(10->初建|CREATE,15->处理中|PROCESSING,20->已入库|STOCK,
            // 25->发券中|ISSUING,30->已完成|FINISH,35->废弃|OBSOLETE,40->异常|EXCEPTION)
            var s = '未知'
            if (params.row.status === 10) {
              s = '初建'
            } else if (params.row.status === 15) {
              s = '处理中'
            } else if (params.row.status === 20) {
              s = '已入库'
            } else if (params.row.status === 25) {
              s = '发券中'
            } else if (params.row.status === 30) {
              s = '已发券完成'
            } else if (params.row.status === 35) {
              s = '废弃'
            } else if (params.row.status === 40) {
              s = '异常'
            }
            return h('div', s)
          }
        },
        {
          title: '导入时间',
          key: 'createTime',
          render: (h, params) => {
            return h('div', params.row.createTime)
          }
        },
        {
          title: this.$t('handle'),
          width: 140,
          key: 'handle',
          align: 'center',
          render: (h, params) => {
            return h('div', handleBtns.map(item => item(h, params, this)))
          }
        }
      ],
      tableData: []
    }
  },
  created () {
    this.vm = this
  },
  methods: Object.assign({}, methods, {
    // ...methods,
  }),
  mounted () {
    this.requestData(this)
  }
}
</script>

<style>
</style>
